<template>
  <div>
    <div>
      <el-row type="left" justify="space-around">
        <el-col :span="6"> </el-col>
        <el-col :span="11"></el-col>
        <el-col :span="7">
          <el-button
            size="small"
            type="primary"
            @click="buffer.Bufferfrom = true"
            >添加</el-button
          ></el-col
        >
      </el-row>
      <gorylist
        :mylist="mylist"
        :calslist="calslist"
        @deleat="cateDela"
        @edit="cateEmits"
      ></gorylist>
      <catelist
        ref="formMenu"
        :buffer="buffer"
        :mylist="mylist"
        @channel="categorylist"
      ></catelist>
    </div>
  </div>
</template>

<script>
import catelist from "../category/components/catelist";
import gorylist from "../category/components/gorylist";
export default {
  name: "",
  components: { catelist, gorylist },
  data() {
    return {
      mylist: [],
      calslist: [],
      buffer: {
        Bufferfrom: false,
      },
    };
  },
  created() {},
  mounted() {
    this.categorylist();
  },
  methods: {
    categorylist() {
      this.$api.cateList({ istree: true }).then((res) => {
        console.log(res);
        this.mylist = res.data.list;
        // console.log(this.mylist);
      });
    },
    cateDela(inof) {
      let { index, row } = inof;
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            let res = await this.$api.cateDel({ id: row.id });
            console.log("结果", res);
            this.mylist = res.data.list;
          } catch {}
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    cateEmits(inof) {
      console.log(inof);
      let { index, row } = inof;
      console.log(row);
      this.buffer.Bufferfrom = true;
      this.$refs.formMenu.form=JSON.parse(JSON.stringify(row));
      this.$refs.formMenu.imageUrl="http://localhost:3000"+row.img;
       console.log(this.$refs.formMenu.form);
    },
  },
};
</script>
<style scoped lang="scss">
.el-row {
  margin-top: 20px;
}
</style>
